package com.eddie.xhttpurlconnection;

import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;


public class MainActivity extends AppCompatActivity {


    private TextView tv_result;


    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv_result = findViewById(R.id.tv_result);

//        String checkUpdate = "http://xmc.wservcie.com/app/checkUpdate?versionCode=2019012127";
//        XHttpUtils.xGet(checkUpdate, new OnRequestListener() {
//            @Override
//            public void onBefore() {
//                Log.e("MyTest", "请求前");
//            }
//
//            @Override
//            public void onSuccess(String result) {
//                Log.e("MyTest", "成功：" + result);
//            }
//
//            @Override
//            public void onFail(int errorCode) {
//                Log.e("MyTest", "失败");
//            }
//        });

//        String login = "http://xmc.wservcie.com/login/password";
//        Map<String, String> param = new HashMap<>();
//        param.put("phone", "18730000000");
//        param.put("password", "123456");
//        XHttpUtils.xPost(login, param, new OnRequestListener() {
//            @Override
//            public void onBefore() {
//                Log.e("MyTest", "请求前");
//            }
//
//            @Override
//            public void onSuccess(String result) {
//                Log.e("MyTest", "成功：" + result);
//            }
//
//            @Override
//            public void onFail(int errorCode) {
//                Log.e("MyTest", "失败");
//            }
//        });

        String downloadUrl = "http://dl1.vcncz.com/upgrade/xmc/2019012527.apk";
        String pathUrl = Environment.getExternalStorageDirectory() + "/ACrash/" + "2019012527.apk";
        XHttpUtils.xDownloadFile(downloadUrl, pathUrl, new OnDownloadListener() {
            @Override
            public void before() {
                Log.e("MyTest", "下载前");
            }

            @Override
            public void curentProgress(int progress) {
                Log.e("MyTest", "进度：" + progress);
            }

            @Override
            public void complete() {
                Log.e("MyTest", "完成");
            }

            @Override
            public void onFail(int errorCode) {
                Log.e("MyTest", "失败：" + errorCode);
            }
        });
    }

}
